package com.holly.unit.deform.designer.kit;


import cn.hutool.core.util.StrUtil;
import com.holly.unit.db.api.constants.DataBaseConstants;
import com.holly.unit.db.api.util.DatabaseUtil;
import com.holly.unit.deform.designer.core.table.*;

import java.sql.SQLException;

/**
 * 类描述: 工具类
 *
 * @author fxr
 * @version 1.0.0
 * @date 2022/7/23 10:38
 */
public class DbTableKit {

    // 开关变量
    public static String DB_TYPE = "";

    // 根据数据库类型构造不同DbTableDDL
    public static IDbTableDDL getDbTableDDL()  throws SQLException{
        IDbTableDDL dbTableDDL = null;
        String dbType = getDatabaseType();
        switch (dbType) {
            case DataBaseConstants.DB_TYPE_MYSQL:
                dbTableDDL = new MySQLDbTableDDLImpl();
                break;
            case DataBaseConstants.DB_TYPE_ORACLE:
                dbTableDDL = new OracleDbTableDDLImpl();
                break;
            case DataBaseConstants.DB_TYPE_SQLSERVER:
                dbTableDDL = new SqlServerDbTableDDLImpl();
                break;
            case DataBaseConstants.DB_TYPE_POSTGRESQL:
                dbTableDDL = new PostgresDbTableDDLImpl();
                break;
            default:
                break;
        }

        return dbTableDDL;
    }

    // 获取数据库类型
    public static String getDatabaseType() throws SQLException {
        if (StrUtil.isNotEmpty(DB_TYPE)) {
            return DB_TYPE;
        }
        return DatabaseUtil.getDatabaseTypeByDataSource();
    }


}
